#include "CFileUtils.h"

void CFileUtils::WriteJsonToFile(const QString& kstrFileName, const QJsonObject& kjsonObject)
{
    QJsonDocument jsonDocument(kjsonObject);
    QFile file(kstrFileName);
    if (file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        file.write(jsonDocument.toJson());
        file.close();
    }
}

QJsonObject CFileUtils::ReadJsonFromFile(const QString& kstrFileName)
{
    QFile file(kstrFileName);
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
        file.close();
        if (doc.isObject())
        {
            return doc.object();
        }
    }
    return QJsonObject();
}